package isjinhao.jlox.grammar.code.represention;

import isjinhao.jlox.grammar.code.visitor.CodeVisitor;
import isjinhao.jlox.grammar.expression.represention.Expression;
import isjinhao.jlox.grammar.statement.represention.Statement;
import lombok.Getter;

import java.util.List;

/**
 * @Author ISJINHAO
 * @Date 2021/2/28 10:14
 */
@Getter
public class IfCode extends Code {

    private Expression ifCondition;

    private Statement ifStatement;

    private List<ElseIfCode> elseIfList;

    private Statement elseStatement;

    public IfCode(Expression ifCondition, Statement ifStatement, List<ElseIfCode> elseIfList, Statement elseStatement) {
        this.ifCondition = ifCondition;
        this.ifStatement = ifStatement;
        this.elseIfList = elseIfList;
        this.elseStatement = elseStatement;
    }

    @Override
    public <R> R accept(CodeVisitor<R> codeVisitor) {
        return codeVisitor.visitIfCode(this);
    }

    public static class ElseIfCode {
        private Expression elseIfCondition;
        private Statement elseIfStatement;
        public Expression getElseIfCondition() {
            return elseIfCondition;
        }
        public Statement getElseIfStatement() {
            return elseIfStatement;
        }
        public ElseIfCode(Expression elseIfCondition, Statement elseIfStatement) {
            this.elseIfCondition = elseIfCondition;
            this.elseIfStatement = elseIfStatement;
        }
    }

}
